import { JJRequest } from '../../request/index'

const jjRequest = new JJRequest({
  baseURL: 'http://yapi.smart-xwork.cn/mock/73302/api',
  interceptors: {
    requestInterceptor: (req) => {
      //此处token在开发中可从localStorage中获取，token一般从服务器获取存在vuex中，然后转存到localStorage中，自己封装关于localStorage的方法，此处用一个常量代替
      //const token = localCache.getCache('token')
      const token = '42589397'
      // @ts-ignore

      req.headers.Authorization = `Bearer ${token}`
      console.log('实例请求拦截器')
      return req
    },
    responseInterceptor: (res) => {
      //此处token在开发中可从localStorage中获取，token一般从服务器获取存在vuex中，然后转存到localStorage中，自己封装关于localStorage的方法，此处用一个常量代替
      //const token = localCache.getCache('token')
      console.log('实例响应拦截器')

      return res
    },
  },
})

const getList = jjRequest.get({
  url: '/task/getList',
  interceptors: {
    requestInterceptor: (req) => {
      console.log('接口请求拦截器')
      return req
    },
    responseInterceptor: (res) => {
      console.log('接口响应拦截器')
      return res
    },
  },
})

export { getList }
